import { request } from '@umijs/max';
import type { DefaultItem } from './List/data';

// 获取树形部门数据接口
export async function queryDeptTree(
  params: {
    pid?: any;
    onlyTop?: string;
    needStr?: boolean;   // 返回的value为name，而不是id
  },
  options?: Record<string, any>,
) {
  return request<DefaultItem>('/api/user/dept', {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}

// 获取指定部门及指定部门下一级部门数据接口
export async function queryDeptById(
  params: {
    id?: any;
  },
  options?: Record<string, any>,
) {
  return request<DefaultItem>('/api/user/deptById', {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}

/** 获取角色权限数据 GET /api/user/role/ */
export async function queryRoleItem() {
  return request<DefaultItem>('/api/user/role/item', {
    method: 'GET',
  });
}

/** 获取用户数据 GET /api/user/item/ */
export async function queryUserItem() {
  return request<DefaultItem>('/api/user/item', {
    method: 'GET',
  });
}
